const login_data = {
    code: '200',
    obj: {
        id: 'test',
        permission: 0
    }
}

const goods_data = {
    code: 200,
    obj: [{
        goodName: "T恤1",
        content: "王炸T恤",
        price: 100,
        img: '',
        imgSrc: ''
    },{
        goodName: "T恤2",
        content: "牛牛T恤",
        price: 150,
        img: '',
        imgSrc: ''
    },{
        goodName: "T恤3",
        content: "珠珠T恤",
        price: 200,
        img: '',
        imgSrc: ''
    }
    ]
}

const user_data = {
    obj: [
    {
        id: 1,
        name: 'zhangsan',
        permission: '1'
    },
    {
        id: 2,
        name: 'lisi',
        permission: '1'
    }]
}


const all_order_data = {
    obj: [
    {
        id: 0,
        userName: 'zhangsan',
        goodName: 'T恤1',
        createTime: '2023-01-01'
    },
    {
        id: 1,
        userName: 'zhangsan',
        goodName: 'T恤2',
        createTime: '2023-01-02'
    },
    {
        id: 2,
        userName: 'lisi',
        goodName: 'T恤1',
        createTime: '2023-02-01'
    },
    {
        id: 3,
        userName: 'lisi',
        goodName: 'T恤2',
        createTime: '2023-02-02'
    }]
}

export const getData = (userName, password) => {
    console.log('>>>>>>', 'mock');
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(login_data)
        }, 50)
    })
}

export const getHomeData = () => {
    console.log(">>>>>>", 'MockHomeData');
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(JSON.parse(JSON.stringify(goods_data.obj)))
        })
    })
}

export const getUserData = () => {
    console.log(">>>>>>", "MockUserData");
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(user_data.obj)
        })
    })
}

export const getAllOrderData = () => {
    console.log(">>>>>>", "getAllOrderData");
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(all_order_data.obj)
        })
    })
}

export const uploadImg = () => {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                imageUrl: 'D:\\Coding\\mall\\src\\assets\\doge.jpg'
            })
        })
    })
}

export const inserGood = ( goodName, content, price, img, imageUrl ) => {
    goods_data.obj.push({
        goodName,
        content,
        price,
        img, 
        imgSrc: imageUrl
    })
    console.log('imgSrc >>>', imageUrl)
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(JSON.parse(JSON.stringify(goods_data)))
        })
    })
}

export const delUser = ( id ) => {
    user_data.obj.forEach( item => {
        console.log("index>>>", item.id)
        if(item.id === id)
        user_data.obj.splice(item, 1)
    });
    // user_data.split
}